
<?
include('includes/common.php');
include_once ('ws/xml_response_process.php');
OB_START();?>

<td id="main_content">
<?

    $request = new WSRequest(XML_API, "ITEM_DETAILS", GETPOST("id"));
    $tour= new XMLprocess($request->wsanswer);
//var_dump($request->wsanswer);
//var_dump($tour);
    ?>
    <div class="category_title"><?=$tour->Title?></div>
    

    <div class="big_tour_top"></div>
    <div class="big_tour_body">
        <div id="book_panel">

        <table border="0" id="book_form" cellpadding="0" cellspacing="3">
<?

if($tour->Code=="STNYC" || $tour->Code=="STBOS" || $tour->Code=="STPHIL" || $tour->Code=="STWDC")
{?>
   <tr>
       <td colspan='3' height='168' valign='top'><br><br>
        <center><b><a href='email_us.php'>Email us</a></b></center><br><br>
       </td>
   </tr>
   <?
   $bottom_block = "<tr><td colspan='2' height='80' valign='top'><br><br>
                       <center><b><a href='email_us.php'>Email us</a></b></center><br><br>
                    </td></tr>";
}else
{


    if($tour->NeedDate==1)
    {
?>

   <script language="javascript" type="text/javascript">
       function get_price(date)
       {
          var req = new JsHttpRequest();
          req.method = "POST";

          // Code automatically called on load finishing.
          req.onreadystatechange = function()
          {
              if (req.readyState == 4)
              {
            	  if (req.responseJS.status == 'ok')
                  {

                     adult_price    = "@ "+req.responseJS.adult+" each";
                     child_price    = "@ "+req.responseJS.child+" each";

                     adult_price_bottom= "@ "+req.responseJS.adult+" each";
                     child_price_bottom= "@ "+req.responseJS.child+" each";



                     window.document.getElementById("adult_price_span").innerHTML = adult_price;
                     window.document.getElementById("child_price_span").innerHTML = child_price;

                     window.document.getElementById("adult_price_span_bottom").innerHTML = adult_price_bottom;
                     window.document.getElementById("child_price_span_bottom").innerHTML = child_price_bottom;

                  	 if(req.responseJS.alert=="1")
                  	 {
                  	   alert(req.responseJS.alert_msg);
                  	 }
            	  } else if(req.responseJS.status == 'error')
                  {
                  	 alert(req.responseJS.error_msg);
                  	 if(req.responseJS.open_calendar=="1")
                  	 {
                  	    imgCalendar_onclick(document.getElementById('memo1'));
                  	 }
            	  }
              }
          }
          req.open(null, 'recalc.php', true);


          var parameters = new Array();
          parameters['item']= "<?=$tour->Code?>";
          parameters['date']= date;
          parameters['ref']= "";//220"; //Affiliate id ??

          // Send data to backend.
          req.send(parameters);
       }

       function checkForm(msg_)
       {

<?


        if($tour->NeedDate==1)
        {
?>
             var tour_date_str = document.getElementById('tour_date').value;
             var monthInteger = parseInt(tour_date_str.substring(0,1))*10+parseInt(tour_date_str.substring(1,2));
             var dayInteger   = parseInt(tour_date_str.substring(3,4))*10+parseInt(tour_date_str.substring(4,5));
             var yearInteger  = parseInt(tour_date_str.substring(6,10));

             if(tour_date_str == "")
             {
                alert("Please select date");
    	   	    //imgCalendar_onclick(document.getElementById('memo1'));
                return false;
     	 	 }else
    	 	 {
    	    	var tour_date = new Date(yearInteger,monthInteger-1,dayInteger);
                var today = new Date();
          	    if(today.setDate(today.getDate()-1) > tour_date)
        	    {
        	           alert("Please select correct date");
        		   	   //imgCalendar_onclick(document.getElementById('memo1'));
        	           return false;
                }
    	    }
<?
        }

        if( isset($tour->CutoffExist))
        {
?>
          	var today = new Date();

            if(today.setDate(today.getDate()+<?=$tour->CutoffValue?>) > tour_date)
            {

               alert("You must book this <?=($tour->Type != 2 ? "tour" : "item")?> at least <?=$tour->CutoffValue?> days in advance.");
               return false;
            }
<?
         }
         if($tour->IsCertainDays==1)
         {
?>
            return checkTourDays(tour_date_str,tour_days,true,msg_);
<?
         }else
         {
?>
     	    return true;
<?
         }
?>
       }//end of checkForm()

       function imgCalendar_onclick(divPosition)
       {
            controlDate = document.getElementById('tour_date');
            popUpCalendar(divPosition,'', 'mm.dd.yyyy');
       }//end of imgCalendar_onclick

       function closeCalendar()
       {
            monthSelected=monthSelected+1;
            if(dateSelected<10){dateSelected="0"+dateSelected;}
            if(monthSelected<10){monthSelected="0"+monthSelected;}
            //controlDate.value=monthSelected+"."+dateSelected+"."+yearSelected;
            //alert(1);
            document.getElementById('tour_date').value          = monthSelected+"."+dateSelected+"."+yearSelected;
            //document.getElementById('tour_date_bottom').value   = document.getElementById('tour_date').value;

            get_price(monthSelected+"."+dateSelected+"."+yearSelected);
            hideCalendar();
          <? if($tour->IsCertainDays==1){ ?> checkTourDays(controlDate.value,tour_days,true,msg); <? } ?>
       }//end of closeCalendar()

       function filter_submit()
       {
    		document.getElementById ("tour_date").readonly = false;
       }
    </script>

        <tr>
            <td id="memo1" name="memo1" class="left_inform" valign="middle">Date:</td>
            <td colspan="2">
                <input type="text" id="tour_date" size="11" name="tour_date" readonly  value="" onclick="imgCalendar_onclick(this);">
            </td>
        </tr>

<?

    }else
    {
?>
    <script language="javascript" type="text/javascript">
       function checkForm(msg_)
       {
          return true;
       }
    </script>
<?
    }

    if($tour->IsCertainDays==1)
    {
?>
    <script language="javascript" type="text/javascript">

    function dayOfWeek(d)
    {
      var myDays= ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"];
      myDate=new Date(d);
      thisDay=myDate.getDay();
      return myDays[thisDay];
    }

    function checkTourDays(tour_date,days,need_alert,msg)
    {
      //alert("checkTourDays:"+tour_date+" | "+msg);
      var myMonths=new Array("January","February","March","April","May","June","July","August","September","October","November","December");

      var monthInteger = parseInt(tour_date.substring(0,1))*10+parseInt(tour_date.substring(1,2));
      var dayInteger   = parseInt(tour_date.substring(3,4))*10+parseInt(tour_date.substring(4,5));
      var yearInteger  = parseInt(tour_date.substring(6,10));

      var monthString  = myMonths[monthInteger-1];

    	today = new Date();

      var formattedDate = monthString+" "+dayInteger+", "+yearInteger;
      var day = dayOfWeek(formattedDate);
      var correctDate = false;
      for (x in days)
      {
        if(days[x] == day){ correctDate = true; break; }
      }
      if(!correctDate)
      {
        //document.getElementById("tourdays").style.color="red";
        if(need_alert) alert(msg);
        return false;
      }else
      {
        //document.getElementById("tourdays").style.color="black";
        return true;
      }
    }

<?
    $message = "This tour departs on ";

    $for_script = "new Array(";

    function check_dayy($day_name){
    $low_case_day = strtolower($day_name);

    if($tour->$low_case_day==1)  {
        if($previous){
            $message.=" and ";
            $for_script.=',';
        }
        $for_script.="'".$day_name."'";
        $message.="<b>".$day_name."s</b>";
        $previous=true;

        }

    }
    $previous = false;
    if($tour->monday==1)   {  $message.="<b>Mondays</b>"; $for_script.="'Monday'"; $previous=true; }

    check_dayy("Tuesday");
    check_dayy("Wednesday");
    check_dayy("Thursday");
    check_dayy("Friday");
    check_dayy("Saturday");
    check_dayy("Sunday");

    $for_script .= ")";
    $message.=" only";
    //echo $message;
    $msg = str_replace('<b>','',$message);
    $msg = str_replace('</b>','',$msg);
    }
    else
    {
    $msg = "";
    $for_script = "";
    echo "<script language=\"javascript\" type=\"text/javascript\">";
    }
    ?>
     var msg = "<?=$msg?>";
     var tour_days = <?=$for_script?>;
     </script>

   <?
      $top_line    = "";
      $field_title = "";
      $vip_group    =   false;


if ($tour->Type == 0)
      {
        //exception..some tours for GROUP
        if(strtolower($tour->Code)=="vip4hr" || strtolower($tour->Code) =="vip6hr" || strtolower($tour->Code) =="vip8hr")
        {
            $field_title = "Group:";
            $vip_group  =   true;
        }else
        {
            $field_title = "Adult:";
        }
      }else
      {
        $top_line    = "<br>";
        $field_title ="Count:";
      }

      if($vip_group){
        $adult_price_text = "$".$tour->AdultPrice;
      }else{
        $adult_price_text = "@ $".$tour->AdultPrice." each";
      }


      $options = "";
      for($i=1;$i<=45;$i++)
      {
        $options .='<option value='.$i.'>'.$i;
      }
?>
        <script>
          function adults_changed()
          {
        	 var adult 				   = document.getElementById("adults");
        	 var adultbottom 		   = document.getElementById("adultsbottom");
        	 adultbottom.selectedIndex = adult.value-1;
          }

          function adultsbottom_changed()
          {
        	 var adult 			 = document.getElementById("adults");
        	 var adultbottom 	 = document.getElementById("adultsbottom");
        	 adult.selectedIndex = adultbottom.value-1;
          }

          function lang_changed()
          {
        	 var lang 				   = document.getElementById("top_lang");
        	 var langbottom 		   = document.getElementById("bottom_lang");
        	 langbottom.value = lang.value;
          }

          function langbottom_changed()
          {
        	 var lang 			 = document.getElementById("top_lang");
        	 var langbottom 	 = document.getElementById("bottom_lang");
        	 lang.value = langbottom.value;
          }

        </script>
        <tr><td colspan="3" style="height:1px"></td></tr>
        <tr>
            <td class="left_inform"><?=$field_title?></td>
            <td width="60px">
                <?if($vip_group){
                        $vip_options="";
                        $group_arr= array(1 => "1-9", 2 => "10-18", 3 => "19-27", 4 => "28-36", 5 => "37-45");
                        for($i=1;$i<5;$i++){
                            $vip_options.='<option value='.$i.'>'.$group_arr[$i].'</option>';

                        }
                    $options=$vip_options;
                }
                    ?>

                    <SELECT name="adults" id="adults" onchange="adults_changed()" style="width: 60px;">
                    <?=$options?>
                    </SELECT>
                </td>
                <td>
                    <span id="adult_price_span"><?=$adult_price_text?></span>

           </td>
        </tr>
<?

        if($vip_group)
        {
?>
            <tr>
                <td class="left_inform" colspan="3">Pickup Location:</td>
            </tr>
            <tr>
                <td class="left_inform" colspan="3">
                    <input name="descr" id="top_descr" style="width:170px;font-size:10px" maxlength="150"></input>
                </td>
            </tr>
            <tr>
                <td class="left_inform">Language:</td>
                <td valign="middle" colspan="2"><?
                        $vip_language="";
                        $language_arr= array(0 => "English", 1 => "Spanish", 2 => "German", 3 => "Italian", 4 => "French",5 => "Portuguese", 6 => "Russian", 7 => "Ukranian", 8=>"Czech", 9 =>"Slovak",10 => "Polish", 11 => "Hebrew", 12 => "Greek", 13 => "Chinese" );
                        for($i=0;$i<14;$i++){
                            $vip_language.='<option value='.$language_arr[$i].'>'.$language_arr[$i].'</option>';

                        }
                ?>  <!--<?print_r($vip_language);?> -->
                    <nobr><SELECT name="lang" id="top_lang" onchange="lang_changed();" style="width: 100px;"><?=$vip_language?></SELECT></nobr>
                </td>
            </tr>
<?

        }

        if($tour->Type == 2)
        {
            $pl = new PickupLocationBO();
            $pl->Load();
            $options = "";
            while ($pl->next())
            {
            	  $options .= '<OPTION VALUE="'.htmlspecialchars($pl->locName).'">'.htmlspecialchars($pl->locName);
            }
?>
            <tr>
                <td  class="left_inform" colspan="3">Pickup Location:</td>
            </tr>
            <tr>
                <td class="left_inform" colspan="3">
                    <SELECT NAME="descr" style="width:170px;"><?=$options?></SELECT>
                </td>
            </tr>
<?

        }elseif($tour->Type == 0)
        {
    	   if($tour->OnlyFor==0)
    	   {
    	       $child_price_text = "@ $".$tour->ChildPrice." each";
    	       $options = "";
    	       for($i=0;$i<=20;$i++)
    	       {
    	          $options .= '<option value="'.$i.'">'.$i;
               }
?>
    <script>
          function childs_changed()
          {
       	  	 var childs 		  = document.getElementById("childs");
       		 var childsbottom 	  = document.getElementById("childsbottom");
    	   	 childsbottom.selectedIndex = childs.value;
          }
          function childsbottom_changed()
          {
       	  	 var childs 		  = document.getElementById("childs");
       		 var childsbottom 	  = document.getElementById("childsbottom");
    	   	 childs.selectedIndex = childsbottom.value;
          }
    </script>
                <tr>
                    <td class="left_inform" >Child:</td>
                    <td>
                        <SELECT onchange="childs_changed()" NAME="childs" id="childs" style="width: 60px;">
                            <?=$options?>
                        </SELECT>
                    </td>
                    <td>
                        <span id="child_price_span"><?=$child_price_text?></span> (<?=$tour->ChildAgeRange?>)
                    </td>
                </tr>

<?

    	   }
       }
?>
                <tr>
                    <td colspan="3" class="left_inform" >
                        <input value="Submit" onFocus="blur()" border="0" type="image" id="book_online_now" src="skin/main/images/book_online_now.png" alt="BOOK ONLINE NOW">
                    </td>
                </tr>
                
<?

   }
?>
                    </table>

     
        <div style="padding:15px 17px 50px">

            <?
               function create_alert($str){
                $tmpl   =   new Template();
                $tmp_str    =   $tmpl->getBlock($str,"[ALERT_START]","[ALERT_END]");
                $tmp_alert  =   $tmpl->cutBlock($str,"[ALERT_START]","[ALERT_END]","$('#messageText').html('".$tmp_str."');$('#message').modal();");


                return  $tmp_alert;
               }

               $tour_itinerary = "";
               if($tour->Type==0)  //0-tour, 1-attraction
               {
                  if(isset($tour->TourLength))
                    $tour_itinerary .= "<b>Tour&nbsp;Length</b><br>".create_alert($tour->TourLength)."<br><br>";

                  if(isset($tour->DepartureLocation))
                    $tour_itinerary .= "<b>Departure&nbsp;Location</b><br>".create_alert($tour->DepartureLocation)."<br><br>";

                  if(isset($tour->DepartureTime))
                    $tour_itinerary .= "<b>Departure&nbsp;Time</b><br>".create_alert($tour->DepartureTime);

               }
               if($tour->Type==1)
               {
                  if(isset($tour->Location))
                    $tour_itinerary .= "<b>Location</b><br>".create_alert($tour->Location)."<br><br>";

                  if(isset($tour->HoursOfOperation))
                    $tour_itinerary .= "<b>Hours&nbsp;of&nbsp;Operation</b><br>".create_alert($tour->HoursOfOperation)."<br><br>";

                  if(isset($tour->AverageVisitTime))
                    $tour_itinerary .= "<b>Average&nbsp;Visit&nbsp;Time</b><br>".create_alert($tour->AverageVisitTime);

               }
            ?>
            <script src="scripts/jquery.simplemodal.js" type="text/javascript"></script>

                <div id="helper"></div>

                <div id="message" style="display: none; text-align: center;">
                <div id="messageText">text</div><br /><br />
                <input type='button' value='Ok' class='modalClose' style='height: 30px; width: 60px;'/>
                </div>

               <?=$tour_itinerary?>
            </div>

    </div>
        <?=isset($tour->Image)?"<img src=\"$tour->Image\">":""?>
        <div class="tour_prices">
            <? if ($tour->AdultPrice>$tour->WebAdultPrice) {?>
            Regular Price:  <span class="old">Adult: $<?=$tour->AdultPrice?>   Child: $<?=$tour->ChildPrice?></span>
            <?}?>
            Web Special:  Adult:  <span class="active"><?=$tour->WebAdultPrice?>$</span>
            Child (Ages <?=$tour->ChildAgeRange?>): <span class="active">$<?=$tour->WebChildPrice?></span>
        </div>
        <?
        if(trim($tour->Note)!="")
        {
           if($tour->NoteLevel==2) //high
              echo "<font style='color:red;font-weight:bold'>";
           elseif($tour->NoteLevel==1) //medium
              echo "<font style='color:white'>";

           else  //low
              echo "<font style='color:yellow'>";
           
           echo $tour->Note."</font><br><br>";
        }
        echo $tour->Description?>
    </div>
    <div class="big_tour_bottom"></div>
    <?
    echo "</td>";
    if(isset($article_)){ echo $article_; }
	$MAIN_BUFFER_CONTENT = ob_get_contents();
	OB_END_CLEAN();

	require_once(SKIN_PATH.'layout_main.php');
?>